home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Lib / test / test_zlib.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-06-23  |  2.8 KB  |  103 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. import zlib
  5. import sys
  6. import imp
  7. import string
  8.  
  9. try:
  10.     t = imp.find_module('test_zlib')
  11.     file = t[0]
  12. except ImportError:
  13.     file = open(__file__)
  14.  
  15. buf = file.read() * 8
  16. file.close()
  17. print hex(zlib.crc32('penguin')), hex(zlib.crc32('penguin', 1))
  18. print hex(zlib.adler32('penguin')), hex(zlib.adler32('penguin', 1))
  19.  
  20. try:
  21.     zlib.compress('ERROR', zlib.MAX_WBITS + 1)
  22. except zlib.error:
  23.     msg = None
  24.     print 'expecting', msg
  25.  
  26.  
  27. try:
  28.     zlib.compressobj(1, 8, 0)
  29. except ValueError:
  30.     msg = None
  31.     print 'expecting', msg
  32.  
  33.  
  34. try:
  35.     zlib.decompressobj(0)
  36. except ValueError:
  37.     msg = None
  38.     print 'expecting', msg
  39.  
  40. x = zlib.compress(buf)
  41. y = zlib.decompress(x)
  42. if buf != y:
  43.     print 'normal compression/decompression failed'
  44. else:
  45.     print 'normal compression/decompression succeeded'
  46. buf = buf * 16
  47. co = zlib.compressobj(8, 8, -15)
  48. x1 = co.compress(buf)
  49. x2 = co.flush()
  50. x = x1 + x2
  51. dc = zlib.decompressobj(-15)
  52. y1 = dc.decompress(x)
  53. y2 = dc.flush()
  54. y = y1 + y2
  55. if buf != y:
  56.     print 'compress/decompression obj failed'
  57. else:
  58.     print 'compress/decompression obj succeeded'
  59. co = zlib.compressobj(2, 8, -12, 9, 1)
  60. bufs = []
  61. for i in range(0, len(buf), 256):
  62.     bufs.append(co.compress(buf[i:i + 256]))
  63.  
  64. bufs.append(co.flush())
  65. combuf = string.join(bufs, '')
  66. decomp1 = zlib.decompress(combuf, -12, -5)
  67. if decomp1 != buf:
  68.     print 'decompress with init options failed'
  69. else:
  70.     print 'decompress with init options succeeded'
  71. deco = zlib.decompressobj(-12)
  72. bufs = []
  73. for i in range(0, len(combuf), 128):
  74.     bufs.append(deco.decompress(combuf[i:i + 128]))
  75.  
  76. bufs.append(deco.flush())
  77. decomp2 = string.join(buf, '')
  78. if decomp2 != buf:
  79.     print 'decompressobj with init options failed'
  80. else:
  81.     print 'decompressobj with init options succeeded'
  82. for sync in [
  83.     zlib.Z_NO_FLUSH,
  84.     zlib.Z_SYNC_FLUSH,
  85.     zlib.Z_FULL_FLUSH]:
  86.     for level in range(10):
  87.         obj = zlib.compressobj(level)
  88.         d = obj.compress(buf[:3000])
  89.         d = d + obj.flush(sync)
  90.         d = d + obj.compress(buf[3000:])
  91.         d = d + obj.flush()
  92.         del obj
  93.     
  94.  
  95.  
  96. def ignore():
  97.     '''An empty function with a big string.
  98.  
  99.     Make the compression algorithm work a little harder.
  100.     '''
  101.     pass
  102.  
  103.